/**
*  \file control_pump_unittest.h
*
*  \brief
*
*  \author Lu Fukui  fukui.lu@linde-china.com
*  \author Wu Pengzhan  pengzhan.wu@linde-china.com
*
*
*
*/
#ifndef CONTROL_PUMP_UNITTEST_H_INCLUDED
#define CONTROL_PUMP_UNITTEST_H_INCLUDED

/*================================================[ public includes  ]================================================*/
#include "../cfg/prj.h"
#include "../test/test.h"
#include "../interpol/interpol_s16_s16.h"
#include "../interpol/interpol_u16_u16.h"
#include "../mlib/max.h"
/*================================================[ public defines   ]================================================*/

/*================================================[ public datatypes ]================================================*/

#define LIFT_POT_CURVE_X_0		0
#define LIFT_POT_CURVE_X_1		1
#define LIFT_POT_CURVE_X_2		2
#define LIFT_POT_CURVE_X_3		3
#define LIFT_POT_CURVE_Y_0		4
#define LIFT_POT_CURVE_Y_1		5
#define LIFT_POT_CURVE_Y_2		6
#define LIFT_POT_CURVE_Y_3		7

/*===============================================[ private datatypes ]================================================*/
typedef struct PUMP_INPUT
{
	S16 lift_switch_1;
	S16 lift_switch_2;
	S16 lift_potentio_ratio;
	S16 tilt_switch;
	S16 aux_switch_1;
	S16 aux_switch_2;
	S16 seat_switch_1;
	U16 battery;

	S16 acc_pedal_ratio;
	S16 truck_speed;
	S16 trac_regeneration_current;
}PUMP_INPUT;

typedef enum LIFT_MODE
{
	one_lift_switch		= 	1,
	two_lift_switch		=	2,
	potentiometer		=	3
}LIFT_MODE;

typedef struct PUMP_PARAMETER
{
	S16 TRUCK_SPEED_THRESHOLD;		//threshold to start pump for steering
	S16 STEER_RPM;
	S16 STEER_CLOSE_DELAY;
	S16 STEER_RAMP_UP;
	S16 STEER_RAMP_DOWN;

	LIFT_MODE LIFT_MODE;
	S16 LIFT_1S_RPM;
	S16 LIFT_2S_RPM_1;
	S16 LIFT_2S_RPM_2;
	S16 LIFT_POT_MIN_PRM;
	S16 LIFT_POT_MAX_RPM;
	S16 LIFT_RAMP_UP;
	S16 LIFT_RAMP_DOWN;

	S16 TILT_RPM;
	S16 TILT_RAMP_UP;
	S16 TILT_RAMP_DOWN;

	S16 AUX1_RPM;
	S16 AUX1_RAMP_UP;
	S16 AUX1_RAMP_DOWN;

	S16 AUX2_RPM;
	S16 AUX2_RAMP_UP;
	S16 AUX2_RAMP_DOWN;

	S16 BATT_CUTBACK_START;
	S16 BATT_CUTBACK_END;
	S16 BATT_RPM_CUTBACK;

	U8	MOTOR_DISCHARGE_ENABLE;
	S16 REGENRATION_CURRENT_THRESHOLD;
	S16 BATT_DISCHARGE_THRESHOLD;		//when soc > this threshold, and regeneration current > setting current, rotate pump with full speed to discharge
}PUMP_PARAMETER;

typedef struct PUMP_OUTPUT
{
	S16 pump_motor_rpm;
	S16 pump_motor_torque;
}PUMP_OUTPUT;

typedef struct PUMP
{
	PUMP_INPUT 		input;
	PUMP_PARAMETER	parameter;
	PUMP_OUTPUT		output;
}PUMP;

typedef struct  PUMP_FALG
{
    BO   steerFlag;
	BO   liftFlag;
	BO   tiltFlag;
	BO   aux1Flag;
	BO   aux2Flag;
}PUMP_FLAG;

typedef enum TMR_STATE
{
	tmrStopped = 0,
	tmrRunning,
	tmrTimeout
}TMR_STATE;

typedef struct TIMER
{
	TMR_STATE state;
	U16 period;
	U16 ticksCnt;
}TIMER;
/** Object definition.
* 
* The struct unittest_obj defines the attribute of an object.
*/
struct unittest_obj
{	
   U8 member_variable;   /**< */
};

/*================================================[ public variables ]================================================*/
extern enum trilean disable_all;
extern TIMER pump_steer_close_delay_tmr;
extern PUMP_FLAG pumpF;
extern F32 steer_current_rpm,	lift_current_rpm, 	tilt_current_rpm, 	aux1_current_rpm, 	aux2_current_rpm;
extern S16 steer_target_rpm, 	lift_target_rpm, 	tilt_target_rpm, 	aux1_target_rpm,	aux2_target_rpm;
extern S16 rpm_output_buffer;
extern S16 lift_pot_curve_x[4];
extern S16 lift_pot_curve_y[4];
extern struct interpol_s16_s16_obj lift_potentio_curve;
extern S16 batt_cutback_curve_x[4];
extern S16 batt_cutback_curve_y[4];
extern struct interpol_s16_s16_obj batt_cutback_curve;

extern PUMP pump;


/*================================================[ inline functions ]================================================*/

/*================================================[ public functions ]================================================*/
/**
*  Constructor.
*
*  Construct an object. 
*
*  \param me Object pointer. NULL will throw an assert.
*
*  \return RC_SUCCESS if successful.
*/
void control_pump_unittest_execute( enum test_mode , U32 time );


/**
 * interfaces of functions to test
 * 
 **/
extern void control_pump_tilt();

extern void control_pump_input_update();

extern void control_pump_parameter_update();

extern void pump_parameter_rx(U16 RxMsgData[4]);

extern void pump_parameter_tx(U16 TxMsgData[4]);

extern void start_timer(TIMER * timer, U16 period);

extern void stop_timer(TIMER * timer);

extern void update_timer(TIMER * timer);

extern void control_pump_steer();

extern void control_pump_lift();

extern void control_pump_tilt();

extern void control_pump_aux1();

extern void control_pump_aux2();

extern void ramp_control(S16 target_value, F32* current_value, S16 ramp_y, S16 ramp_up_x, S16 ramp_down_x);

extern void output_max_rpm();

extern RC interpol_s16_s16_construct( struct interpol_s16_s16_obj *me, pal_size_t count, S16 const * p_x, S16 const * p_y );

extern void batt_cutback_control();

extern void pump_motor_discharge_control();

/**
 * stub function defined in c file, for the stubing function calls in function to test.
 * 
 **/
void STUB_control_pump_input_update();
void STUB_control_pump_parameter_update();
void STUB_pump_parameter_rx(U16 RxMsgData[4]);
void STUB_pump_parameter_tx(U16 TxMsgData[4]);
void STUB_start_timer(TIMER * timer, U16 period);
void STUB_stop_timer(TIMER * timer);
void STUB_update_timer(TIMER * timer);
void STUB_control_pump_steer();
void STUB_control_pump_lift();
void STUB_control_pump_tilt();
void STUB_control_pump_aux1();
void STUB_control_pump_aux2();
void STUB_ramp_control(S16 target_value, F32* current_value, S16 ramp_y, S16 ramp_up_x, S16 ramp_down_x);
void STUB_output_max_rpm();
RC STUB_interpol_s16_s16_construct( struct interpol_s16_s16_obj *me, pal_size_t count, S16 const * p_x, S16 const * p_y );
void STUB_batt_cutback_control();
void STUB_pump_motor_discharge_control();
/*====================================================================================================================*/

#endif

/***********************************************************************************************************************
*                             Copyright 2020 Linde Material Handling. All rights reserved.                             *
***********************************************************************************************************************/
